package org.example.dao;

import org.apache.ibatis.annotations.*;
import org.example.pojo.Order;

import java.util.List;

public interface OrderDAO {
    @Select("select * from tb_order where id = #{id}")
    @Results(id = "orderMap", value = {
            @Result(property = "user", column = "user_id",
                    one = @One(select = "org.example.dao.UserDAO.findById"))
    })
    public Order findById(Integer id);

    @Select("select * from tb_order")
    @ResultMap("orderMap")
    public List<Order> findAll();

    @Insert("insert into tb_order values(null, #{number}, #{user.id})")
    public boolean save(Order order);

    @Update("update tb_order set number = #{number}, user_id = #{user.id} where id = #{id}")
    public boolean update(Order order);

    @Delete("delete from tb_order where id = #{id}")
    public boolean delete(Order  order);

    @Select("select * from tb_order where user_id = #{userId}")
    public List<Order> findByUserId(Integer userId);
}
